package com.zzyweb.demomp.utils;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author zhiyi
 * @date 9/9/25
 **/
@Data
public class ResultObject {
    // 200 成功 400 为找到资源 500异常
    private Integer code;
    private String msg;
    private boolean success;
    private Object data;

    private ResultObject(Integer code, String msg, boolean success, Object data) {
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.data = data;
    }

    public static ResultObject ok() {
        return new ResultObject(200,"成功访问", true, null);
    }

    public static ResultObject ok(Object data) {
        return new ResultObject(200,"成功访问", true, data);
    }

    public static ResultObject error() {
        return new ResultObject(500,"访问失败", false, null);
    }

    public ResultObject code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultObject msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    public ResultObject success(boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResultObject data(Object data) {
        this.setData(data);
        return this;
    }
}
